package org.qpcr.community.project.service;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 基于用户提供的导出表头，定义各个 sheet 的「表头 → 存储字段」映射。
 */
public final class SheetMappings {
    private SheetMappings() {}

    public static Map<String, List<MappingRule>> all() {
        Map<String, List<MappingRule>> map = new HashMap<>();

        // 温度（严格按提供的表头，不做扩展）
        map.put("温度", Arrays.asList(
            MappingRule.of("sample_time", "Time (s)"),
            MappingRule.of("temp_rtd_expect", "RTD_Des (Celsius Degree)"),
            MappingRule.of("reserved_power", "Reagent_Tar(Celsius Degree)"),
            MappingRule.of("temp_goal", "Set (Celsius Degree)"),
            MappingRule.of("temp_forecast", "Reagent (Celsius Degree)"),
            MappingRule.of("temp_rtd_actual", "RTD_Real (Celsius Degree)"),
            MappingRule.of("temp_cold_head", "Cooler (Celsius Degree)"),
            MappingRule.of("Assisted_RTD_A", "Assisted_RTD_A(Celsius Degree)"),
            MappingRule.of("Assisted_RTD_B", "Assisted_RTD_B(Celsius Degree)"),
            MappingRule.of("Assisted_RTD_C", "Assisted_RTD_C(Celsius Degree)")
        ));

        // 电压电流（严格按提供的表头，不做扩展）
        map.put("电压电流", Arrays.asList(
            MappingRule.of("sample_time", "Time (s)"),
            MappingRule.of("rtd_vol", "Main_Voltage (V)"),
            MappingRule.of("rtd_cur", "Main_Current (A)"),
            MappingRule.of("AVoltage", "A_Voltage (V)"),
            MappingRule.of("ACurrent", "A_Current (A)"),
            MappingRule.of("BVoltage", "B_Voltage (V)"),
            MappingRule.of("BCurrent", "B_Current (A)"),
            MappingRule.of("CVoltage", "C_Voltage (V)"),
            MappingRule.of("CCurrent", "C_Current (A)")
        ));

        // 扩增（严格按提供的表头，不做扩展）
        map.put("扩增", Arrays.asList(
            MappingRule.of("cycle", "Cycle"),
            MappingRule.of("ch1_light", "Fluore (VIC)"),
            MappingRule.of("ch2_light", "Fluore (Cy5)"),
            MappingRule.of("ch3_light", "Fluore (FAM)"),
            MappingRule.of("ch4_light", "Fluore (ROX)")
        ));

        // 荧光（电压）（严格按提供的表头，不做扩展）
        map.put("荧光（电压）", Arrays.asList(
            MappingRule.of("count", "Cycle"),
            MappingRule.of("ch1_value", "Fluore(VIC)","Fluore (VIC)"),
            MappingRule.of("ch2_value", "Fluore(Cy5)","Fluore (Cy5)"),
            MappingRule.of("ch3_value", "Fluore(FAM)","Fluore (FAM)"),
            MappingRule.of("ch4_value", "Fluore(ROX)","Fluore (ROX)"),
            MappingRule.of("ch1_original", "Fluore(VIC) Original(0.1V)","Fluore (VIC) Original(0.1V)"),
            MappingRule.of("ch2_original", "Fluore(Cy5) Original(0.1V)","Fluore (Cy5) Original (0.1V)"),
            MappingRule.of("ch3_original", "Fluore(FAM) Original(0.1V)","Fluore (FAM) Original (0.1V)"),
            MappingRule.of("ch4_original", "Fluore(ROX) Original(0.1V)","Fluore (ROX) Original (0.1V)")
        ));

        // 荧光(源数据)（严格按提供的表头，不做扩展）
        map.put("荧光(源数据)", Arrays.asList(
            MappingRule.of("count", "Cycle"),
            MappingRule.of("vic", "Fluore(VIC)","Fluore (VIC)"),
            MappingRule.of("cy5", "Fluore(Cy5)","Fluore (Cy5)"),
            MappingRule.of("fam", "Fluore(FAM)","Fluore (FAM)"),
            MappingRule.of("rox", "Fluore(ROX)","Fluore (ROX)"),
            MappingRule.of("ch_vic", "Fluore(VIC) Original","Fluore (VIC) Original"),
            MappingRule.of("ch_cy5", "Fluore(Cy5) Original","Fluore (Cy5) Original"),
            MappingRule.of("ch_fam", "Fluore(FAM) Original","Fluore (FAM) Original"),
            MappingRule.of("ch_rox", "Fluore(ROX) Original","Fluore (ROX) Original")
        ));
        // 荧光(源数据)（严格按提供的表头，不做扩展）
        map.put("荧光（原数据）", Arrays.asList(
                MappingRule.of("count", "Cycle"),
                MappingRule.of("vic", "Fluore(VIC)","Fluore (VIC)"),
                MappingRule.of("cy5", "Fluore(Cy5)","Fluore (Cy5)"),
                MappingRule.of("fam", "Fluore(FAM)","Fluore (FAM)"),
                MappingRule.of("rox", "Fluore(ROX)","Fluore (ROX)"),
                MappingRule.of("ch_vic", "Fluore(VIC) Original","Fluore (VIC) Original"),
                MappingRule.of("ch_cy5", "Fluore(Cy5) Original","Fluore (Cy5) Original"),
                MappingRule.of("ch_fam", "Fluore(FAM) Original","Fluore (FAM) Original"),
                MappingRule.of("ch_rox", "Fluore(ROX) Original","Fluore (ROX) Original")
        ));
        // CT（严格按提供的表头，不做扩展）
        map.put("CT", Arrays.asList(
            MappingRule.of("vic", "Fluore (VIC)"),
            MappingRule.of("cy5", "Fluore (Cy5)"),
            MappingRule.of("fam", "Fluore (FAM)"),
            MappingRule.of("rox", "Fluore (ROX)")
        ));

        // 熔解（原数据）（严格按提供的表头，不做扩展）
        map.put("熔解（原数据）", Arrays.asList(
            MappingRule.of("temperatur1", "VIC_T (Celsius Degree)"),
            MappingRule.of("ch1_light", "Fluore (VIC)"),
            MappingRule.of("temperatur2", "Cy5_T (Celsius Degree)"),
            MappingRule.of("ch2_light", "Fluore (Cy5)"),
            MappingRule.of("temperatur3", "FAM_T (Celsius Degree)"),
            MappingRule.of("ch3_light", "Fluore (FAM)"),
            MappingRule.of("temperatur4", "ROX_T (Celsius Degree)"),
            MappingRule.of("ch4_light", "Fluore (ROX)")
        ));

        // 熔解（后处理）（严格按提供的表头，不做扩展）
        map.put("熔解（后处理）", Arrays.asList(
            MappingRule.of("temperatur1", "T_VIC"),
            MappingRule.of("ch1_light_d", "Diff (VIC)"),
            MappingRule.of("temperatur2", "T_Cy5"),
            MappingRule.of("ch2_light_d", "Diff (Cy5)"),
            MappingRule.of("temperatur3", "T_FAM"),
            MappingRule.of("ch3_light_d", "Diff (FAM)"),
            MappingRule.of("temperatur4", "T_ROX"),
            MappingRule.of("ch4_light_d", "Diff (ROX)")
        ));

        // 熔解结果（严格按提供的表头，不做扩展）
        map.put("熔解结果", Arrays.asList(
            MappingRule.of("ch1_light_t", "Tm_VIC"),
            MappingRule.of("ch1_light_rm", "Rm_VIC"),
            MappingRule.of("ch2_light_t", "Tm_Cy5"),
            MappingRule.of("ch2_light_rm", "Rm_Cy5"),
            MappingRule.of("ch3_light_t", "Tm_FAM"),
            MappingRule.of("ch3_light_rm", "Rm_FAM"),
            MappingRule.of("ch4_light_t", "Tm_ROX"),
            MappingRule.of("ch4_light_rm", "Rm_ROX")
        ));

        return map;
    }

    /**
     * 业务ID(bizId) -> sheet 名称 列表。
     * 严格按用户提供的关系：
     * TemperatureReportData -> 温度、电压电流
     * MeteringDataReport -> 荧光（电压）
     * MeteringSaveData -> 荧光(源数据)
     * AmplificationData -> 扩增
     * MeltCurveData -> 熔解（原数据）
     * MeltCurveCalcData -> 熔解（后处理）、熔解结果
     * 无：实验信息、状态信息、CT
     */
    public static Map<String, List<String>> bizIdToSheets() {
        Map<String, List<String>> map = new HashMap<>();
        map.put("TemperatureReportData", Arrays.asList("温度", "电压电流"));
        map.put("MeteringDataReport", Arrays.asList("荧光（电压）"));
        map.put("MeteringSaveData", Arrays.asList("荧光(源数据)"));
        map.put("AmplificationData", Arrays.asList("扩增"));
        map.put("MeltCurveData", Arrays.asList("熔解（原数据）"));
        map.put("MeltCurveCalcData", Arrays.asList("熔解（后处理）", "熔解结果"));
        return map;
    }

    /**
     * sheet 名称 -> 业务ID(bizId)。
     * 对于一对多场景（一个 bizId 对应多个 sheet），此处做反向唯一映射：
     *   - 温度、电压电流 -> TemperatureReportData
     *   - 荧光（电压） -> MeteringDataReport
     *   - 荧光(源数据) -> MeteringSaveData
     *   - 扩增 -> AmplificationData
     *   - 熔解（原数据） -> MeltCurveData
     *   - 熔解（后处理）、熔解结果 -> MeltCurveCalcData
     * 无：实验信息、状态信息、CT
     */
    public static Map<String, String> sheetToBizId() {
        Map<String, String> map = new HashMap<>();
        map.put("温度", "TemperatureReportData");
        map.put("电压电流", "TemperatureReportData");
        map.put("荧光（电压）", "MeteringDataReport");
        map.put("荧光（原数据）", "MeteringSaveData");
        map.put("扩增", "AmplificationData");
        map.put("熔解（原数据）", "MeltCurveData");
        map.put("熔解（后处理）", "MeltCurveCalcData");
        map.put("熔解结果", "MeltCurveCalcData");
        return map;
    }
}


